# Maintainer: Danila Tikhonov <danila@jiaxyga.com>
# Co-Maintainer: Jens Reidel <adrian@travitia.xyz>

pkgname=soc-qcom-sm7150
pkgdesc="Common package for Qualcomm SM7150 devices"
pkgver=1
pkgrel=1
url="https://postmarketos.org"
license="BSD-3-Clause"
arch="aarch64"
options="!check !strip !archcheck !tracedeps pmb:cross-native"
depends="
	swclock-offset
"
subpackages="
	$pkgname-nonfree-firmware:nonfree_firmware
	$pkgname-nonfree-firmware-openrc:nonfree_firmware_openrc
	$pkgname-unl0kr-quirk:unl0kr_quirk
"

_gpufw_commit="bad0fd43728e8e2efd92e4b13f270bb27aa68272"
source="
	$pkgname-$_gpufw_commit.tar.gz::https://github.com/sm7150-mainline/firmware-adreno-gpu/archive/$_gpufw_commit.tar.gz
	10-unl0kr.conf
	30-initramfs-firmware.files
	90-feedbackd-aw8695.rules
	90-feedbackd-pm6150.rules
"

package() {
	install -Dm644 "$srcdir"/90-feedbackd-aw8695.rules \
		"$pkgdir"/usr/lib/udev/rules.d/90-feedbackd-aw8695.rules

	install -Dm644 "$srcdir"/90-feedbackd-pm6150.rules \
		"$pkgdir"/usr/lib/udev/rules.d/90-feedbackd-pm6150.rules
}

nonfree_firmware() {
	depends="
		linux-firmware-ath10k
		linux-firmware-qca
		linux-firmware-qcom
		pd-mapper
		tqftpserv
		msm-modem
		msm-modem-uim-selection"
	mkdir "$subpkgdir"

	# We will get all other Adreno GPU FWs from linux-firmware-qcom
	install -Dm644 "$srcdir/firmware-adreno-gpu-$_gpufw_commit"/a615_zap.mbn -t \
		"$subpkgdir"/lib/firmware/qcom

	install -Dm644 "$srcdir/30-initramfs-firmware.files" -t \
		"$subpkgdir"/usr/share/mkinitfs/files
}

nonfree_firmware_openrc() {
	install_if="$pkgname-nonfree-firmware=$pkgver-r$pkgrel openrc"
	install="$subpkgname.post-install"
	depends="
		pd-mapper-openrc
		tqftpserv-openrc
		"

	mkdir -p "$subpkgdir"
}

unl0kr_quirk() {
	# With fbdev emulation enabled, unl0kr needs to force refresh on some panels
	install -Dm644 "$srcdir"/10-unl0kr.conf \
		"$subpkgdir"/etc/unl0kr.conf.d/10-unl0kr.conf
}

sha512sums="
93a57ec896c35537587190e2da7c6e97025e8df90603b6bc5309d24404bf96cdf54187ebd53c6006d5772adf152a09e0e7c1b3481f5cfe48a0b6f1bfc8c0ac1a  soc-qcom-sm7150-bad0fd43728e8e2efd92e4b13f270bb27aa68272.tar.gz
f700af3145b79d1ef9edfb22982899b25cabfb212f9620dcbd3a2e6f44b5ad591e0a66056c6fcd66c3fde89a2b5f551e8a8fe2e65cf0e2a48adec57c027d7825  10-unl0kr.conf
389a4716a9f92871cb0ded771f27480a6657f26f6e5a6db7908e7cb26a36d5dcf60e3bfcbdb86c1a31d643016817798a5ca776e4cf564515336125a483cd07f5  30-initramfs-firmware.files
2974ccc172bf1299daeb0bc746879b3a1db1fbc3a2b163a02a6554fed6ed9f733144bcf976cd2441c5664d496dcce3ae943f4314c653470dc07dda0de5ad632b  90-feedbackd-aw8695.rules
90fca4a3291a2c84c0b20e41308c4698374ba896e9365ca80dbfd0c0c4f7dc08317f3dd865a3c7f6707c81b02f5bb24136d1172253d2e4fdd50039bbbf02a178  90-feedbackd-pm6150.rules
"
